Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
safe-identifier
Advanced tools
Sanitize strings for use as JavaScript identifiers & property names
Sanitize strings for use as JavaScript identifiers & property names.
npm install --save safe-identifier
import { identifier, property } from 'safe-identifier'
identifier('Foo') === 'Foo'
identifier('enum') === '_enum'
identifier('my var', true) === 'my_var_hk17pp'
identifier(' my \0var ', true) === 'my_var_1d8fi3'
property('Foo', 'bar') === 'Foo.bar'
property('Foo', 'bar\nbar') === 'Foo["bar\\nbar"]'
property(null, 'foo') === 'foo'
property(null, 'void') === '"void"'
identifier(key: string, unique: boolean): string
Sanitize a string for use as an identifier name
Replaces invalid character sequences with _
and may add a _
prefix if the
resulting name would conflict with a JavaScript reserved name, covering all
standards from ES3 up to ES2018, along with current
active proposals.
If unique
is true, a 32-bit hash of the key
is appended to the result in
order to help ensure that different inputs produce different outputs.
property(obj: string?, key: string): string
Sanitize a string for use as a property name
By default uses obj.key
notation, falling back to obj["key"]
if the key
contains invalid characters or is an ECMAScript 3rd Edition reserved word
(required for IE8 compatibility). If obj
is empty, returns only the possibly
quoted property key. The correctness of obj
is not checked.
FAQs
Sanitize strings for use as JavaScript identifiers & property names
The npm package safe-identifier receives a total of 515,752 weekly downloads. As such, safe-identifier popularity was classified as popular.
We found that safe-identifier demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.